home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 8_12.lha / 8_12 / 8_12a3.c < prev    next >
C/C++ Source or Header  |  1993-08-08  |  2KB  |  63 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. / reallocate the internal streambuf buffer
  6. nt extrabuf::reallocate()
  7.  
  8. /cerr << "reallocate() invoked, dobuffering=" << dobuffering << "\n"; // DELETE
  9. /cerr << "\tbase=" << form("%#x", base) << "\n";    // DELETE
  10. /cerr << "\tgptr=" << form("%#x", gptr) << "\n";    // DELETE
  11. /cerr << "\tpptr=" << form("%#x", pptr) << "\n";    // DELETE
  12. /cerr << "\teptr=" << form("%#x", eptr) << "\n";    // DELETE
  13.    // the buffer is full
  14.    if ((gptr == base) || dobuffering)
  15. {
  16. int curlength = eptr - base;
  17. int newlength = curlength + BUFSIZ;
  18. char *obase = base;
  19.  
  20. base = new char[newlength];
  21. if (base != NULL)
  22.     {
  23.     gptr = base + (gptr - obase);
  24.     pptr = base + (pptr - obase);
  25.     eptr = base + newlength;
  26.     memcpy(base, obase, curlength);
  27.     delete obase;
  28. /cerr << "\t----------------\n";    // DELETE
  29. /cerr << "\tbase=" << form("%#x", base) << "\n";    // DELETE
  30. /cerr << "\tgptr=" << form("%#x", gptr) << "\n";    // DELETE
  31. /cerr << "\tpptr=" << form("%#x", pptr) << "\n";    // DELETE
  32. /cerr << "\teptr=" << form("%#x", eptr) << "\n";    // DELETE
  33. /cerr << "\treturning 0\n";            // DELETE
  34.     return 0;
  35.     }
  36.  
  37. // the allocation failed
  38. else
  39.     {
  40.     base = obase;
  41. /cerr << "\treturning -1\n";            // DELETE
  42.     return EOF;
  43.     }
  44. }
  45.  
  46.    // there's some room at the beginning of the buffer
  47.    else
  48. {
  49. int length = pptr - gptr;
  50. if (length > 0)
  51.     memmove(base, gptr, length);
  52. gptr = base;
  53. pptr = base + length;
  54. /cerr << "\t----------------\n";    // DELETE
  55. /cerr << "\tbase=" << form("%#x", base) << "\n";    // DELETE
  56. /cerr << "\tgptr=" << form("%#x", gptr) << "\n";    // DELETE
  57. /cerr << "\tpptr=" << form("%#x", pptr) << "\n";    // DELETE
  58. /cerr << "\teptr=" << form("%#x", eptr) << "\n";    // DELETE
  59. /cerr << "\treturning 0\n";            // DELETE
  60. return 0;
  61. }
  62.  
  63.